/* ************************************************************************
> File Name:     4.c
> Author:        zhfu
> mail:          3346897597@qq.com
> Created Time:  2022年04月27日 星期三 11时28分51秒
> Description:   
 ************************************************************************/
#include<stdio.h>
#include"qsort.h"

typedef struct {
     const char *name;
     int score;
} student_t;

int cmp_student(void *a, void *b)
{
    if(((student_t *)a)->score > ((student_t *)b)->score)
	    return 1;
    else if(((student_t *)a)->score == ((student_t *)b)->score)
	    return 0;
    else
	    return -1;
}

int main(void)
{
    student_t list[6] = {{"Tom", 68}, {"Jerry", 72},
		                 {"Moby", 60}, {"Kirby", 89},
                         {"zhfu", 69}, {"xysong", 99}};
    student_t *plist[6] = {&list[0], &list[1], &list[2], &list[3], &list[4], &list[5]};

    qsort(cmp_student, 0, 5, (void **)plist);
    
    for (int i = 0; i < 6; ++i){
        printf("%s\n", plist[i]->name);
    }

}

